/**
 * Created by Jay on 2016/6/13.
 */
/*url: http://blog.allenm.me/2012/01/jquery_deferred_promise_method/*/
function report_user() {
        $("body").off();
    /*search*/
    $("body").on("click",".rep_search",function(){
        var this_search=$(".rep_search_real").val();
        //console.log("click");
        if(this_search==" "){
            return;
        }
        //var informReason=["色情低俗","广告骚扰","政治敏感","欺诈骗钱","违法","侵权举报"];
        //var status=["审核中","举报成功","举报失败"];
        //for(var i=0;i<informReason.length;i++){
        //    if(~(this_search.indexOf(informReason[i]))){
        //        var search_main={informReason:this_search,pageSize:10, pageNo:1};
        //        break;
        //    }else if(~(this_search.indexOf(status[i]))){
        //        var search_main={status:this_search,pageSize:10, pageNo:1};
        //        break;
        //    }
        //}
        //console.log(this_search);
        $.ajax({
                url:"memberController/searchInformUserInfo",
                method:"POST",
                data:{pageSize:10,pageNo:1,informReason:$("#select_s").val(),status:$("#select_d").val()}
            })
            .done(function(data){
                console.log("aa");
                console.log(data);
                //data.result.resultList=data.result;
                set_seqsum(
                    {
                        pageNo:data.result.pageNo,
                        pageSize:data.result.pageSize
                    }
                );
                create_page({
                    url:"memberController/searchInformUserInfo",
                    method:"POST",
                    data:data,
                    temp:"getColumnTableData_report",
                    contain:"#ColumnTableData_report",
                    prePageSize:data.result.pageSize,
                    prepageNo:data.result.pageNo
                })//生成分页
                var return_data=1*data.result.pageNo;//返回的首位数
                sessionStorage.setItem("pageNo",data.result.pageNo);
                sessionStorage.setItem("pageSize",data.result.pageSize);
                sessionStorage.setItem("return_data",return_data);
                var page=get_page_size();
                mccmsa.getHtmlFromLocalTemplate({   //将数据打包到模版丢进容器
                    templateId:"getColumnTableData_report",
                    container:$("#ColumnTableData_report"),
                    data:data,
                    callback:function(){
                    }
                })
            })
            .fail(function(){
                console.log("fail");
            })
    })
    /*search end*/
    $.ajax({
            url: "memberController/showInformUserInfo",
            method: "get",
            data: {pageSize: 10, page: 1}
    })/*请求*/
    /*成功*/
    .done(function(data){
        //console.log("text");
        //console.log(data);
        /*设置序号*/
        sessionStorage.setItem("this_page_click_num", 1);//初始化为1；
        sessionStorage.setItem("create_num", 1);//初始化为1
        /*create_page*/
        set_seqsum(
            {
                    pageNo: data.result.pageNo,
                    pageSize: data.result.pageSize
            }
        );
        create_page({
            url: "memberController/showInformUserInfo",
            temp: "getColumnTableData_report",
            contain: "#ColumnTableData_report",
            data: data,
            method: "get",
            prePageSize: data.result.pageSize,
            prepageNo: data.result.pageNo
        });
        /*handlebar*/
        /*要回调的~~~异步*/
        /*url: http://blog.allenm.me/2012/01/jquery_deferred_promise_method/*/
        function wait() {
            var dtd = $.Deferred();/*声明Deferred*/
            mccmsa.getHtmlFromLocalTemplate({   //将数据打包到模版丢进容器
                templateId: "getColumnTableData_report",
                container: $("#ColumnTableData_report"),
                data: data,
                callback: function () {
                    dtd.resolve(); // 改变deferred对象的执行状态
                    return dtd.promise(); // 返回promise对象 因为 deferred是全局的
                                         // deferred.promise() 只是阻止其他代码来改变这个 deferred 对象的状态
                                        //作用也不是保证目前的状态不变，它只是保证你不能通过 deferred.promise() 返回的 deferred promise 对象改变
                }
            })
        }
        $.when(wait())
        .done(function(){
            $("body").on("click", ".report_detail", function () {
            var type = $(this).attr("data-report_id");
                    mccmsa.goTo("report_user_detail", "report_user", {type: type});
            })//goto detail

            /*删除举报*/
            $("body").on("click", ".report_delete_s",function(){
                var inform_id = $(this).attr("data-this_id");
                    delete_tips({
                        url: "memberController/delInformRecord",
                        data: {informId: inform_id},
                        method: "get",
                        content: "确认要删除？",
                        alert: "删除成功"
                    })
            })

            /*举报信息*/
            $("body").on("click", ".report_read",function(){
                    var content = " ";
                    var inform_id = $(this).attr("data-this_id");
                    var status = $(this).attr("data-status");
                    if (status == "0") {
                        layer.alert("已经操作过了");
                        return;
                    }
                    if (status == 1) {
                        content = "确认要举报成功?"
                    }
                    else if (status == 2) {
                        content = "确认要举报失败"
                    }
                    delete_tips({
                        url: "memberController/auditInformInfo",
                        data: {informId: inform_id, status: status},
                        method: "get",
                        content: content,
                        alert: "操作成功"
                    })
            })
        })
    /*出错*/
    .fail(function(){
                layer.alert("网络出错");
                console.log("网络出错了");
    })
    })
}